package main

import (
	"context"
	"fmt"
	"google.golang.org/grpc"
	"mxshop/mxshop_srvs/inventory_srv/proto"
)

var inv proto.InventoryClient
var conn *grpc.ClientConn

func Init() {
	var err error
	conn, err = grpc.Dial("0.0.0.0:63049", grpc.WithInsecure())
	if err != nil {
		panic(err)
	}

	inv = proto.NewInventoryClient(conn)
}

func TestGetSubCategory() {
	_, err := inv.Sell(context.Background(), &proto.SellInfo{
		GoodsInfo: []*proto.GoodsInvInfo{
			{GoodsId: 421, Num: 10},
			{GoodsId: 422, Num: 10},
		},
	})
	if err != nil {
		panic(err)
	}
	fmt.Println("成功")
}

func TestSetInv(goodsId, Num int32) {
	_, err := inv.SetInv(context.Background(), &proto.GoodsInvInfo{
		GoodsId: goodsId,
		Num:     Num,
	})
	if err != nil {
		panic(err)
	}
	fmt.Println("设置库存成功")
}

func main() {
	Init()

	TestGetSubCategory()
	//var i int32
	//for i = 421; i <= 840; i++ {
	//	TestSetInv(i, 100)
	//}
	conn.Close()

}
